/*
 * webstartpoint: com.ctvit.framework.service.BlazeDSLoginListener.java Create On Dec 15, 2008 5:58:15 PM By Q-Wang
 * $Header: /home/cvsroot/ctvit/messgeCenter/src/com/ctvit/framework/service/BlazeDSLoginListener.java,v 1.1 2015/12/18 01:17:30 yushihao Exp $
 */
package com.ctvit.framework.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;

import com.ctvit.framework.web.context.ContextHolder;

import flex.messaging.HttpFlexSession;

/**
 * @author Q-Wang
 *
 */
public class BlazeDSLoginListener implements ApplicationListener {

	protected final Log log = LogFactory.getLog(getClass());
	
	/**
	 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
	 */
	public void onApplicationEvent(ApplicationEvent event) {
		if (event instanceof AuthenticationSuccessEvent) {
			AuthenticationSuccessEvent successEvent = (AuthenticationSuccessEvent) event;
			Authentication authentication = successEvent.getAuthentication();
			if (log.isDebugEnabled()) {
				log.debug("Processing BlazeDS Login:" + authentication);
			}
			HttpFlexSession.getFlexSession(ContextHolder.getHttpRequest()).setUserPrincipal(authentication);
		}
	}

}
